package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Screening;
import com.zretc.service.ScreeningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @author 周文涛
 * 后端场次管理（待定：排场优化）
 */
@RestController
@RequestMapping("back")
public class BackScreeningController {
    @Autowired
    private ScreeningService screeningService;

    // 修改
    @PutMapping("screening")
    public boolean updateScreening(@RequestBody Screening screening){
        return screeningService.update(screening);
    }
    // 查询
    @GetMapping("screening")
    public PageInfo<Screening> getScreeningList(String limit,
                                                String page,
                                                String startTime,
                                                String endTime,
                                                String filmId,
                                                String auditoriumsId){
        HashMap<String, String> condition = new HashMap<>();
        condition.put("pageSize",limit);
        condition.put("pageNum",page);
        condition.put("startTime",startTime);
        condition.put("endTime",endTime);
        condition.put("filmId",filmId);
        condition.put("auditoriumsId",auditoriumsId);
        return screeningService.getScreeningList(condition);
    }
    // 删除
    @DeleteMapping("screening/{id}")
    public boolean deleteScreening(@PathVariable("id") String screeningId){
        return screeningService.delete(screeningId);
    }
    // 添加
    @PostMapping("screening")
    public boolean saveScreening(@RequestBody Screening screening){
        return screeningService.save(screening);
    }

}
